package Object;

import java.util.Objects;

//public static boolean equals(Object a, Object b)// 比较两个对象是否相等
/* public static boolean isNull(Object obj)	// 判断对象是否为null
public static boolean nonNull(Object obj)// 判断对象是否不为null
 */
public class objectdemo6 {
    public static void main(String[] args) {
        Student s1 = null;
        Student s2 = new Student("zhangsan", 18);
        //判断对象是否为null
        boolean result = Objects.equals(s1, s2);
        System.out.println(result);//false
        //细节:
        //1.方法的底层会判断s1是否为null,如果为null,直接返回false
        //2.如果s1不为null,那就利用s1再次调用equals方法
        //3.此时s1是Student类型,所以最终还是会调用Student类型中的equals方法
        //如果没有重写,比较的是地址值,如果重写了,比较的就是属性值了

        Student s3 = new Student("zhangsan", 18);
        Student s4 = null;
        System.out.println(Objects.isNull(s3));//// 判断对象是否为null,为null返回true
        System.out.println(Objects.isNull(s4));
        System.out.println("---------------------------");
       // public static boolean nonNull(Object obj)// 判断对象是否不为null
        Student s5 = new Student("zhangsan", 18);
        Student s6 = null;
        System.out.println(Objects.nonNull(s5));//判断对象是否为不null,如果不为null返回true
        System.out.println(Objects.nonNull(s6));



    }
}
